package com.gitee.wsl.ext.collection


fun <T, R> Iterable<T>.foldWhileNotNull(initial: R?, operation: (acc: R, T) -> R?): R? {
    var accumulator = initial ?: return null
    for (element in this) {
        accumulator = operation(accumulator, element) ?: return null
    }
    return accumulator
}
